package seqlist.oj;

/**
 * @Author: yuisama
 * @Date: 2019/12/6 16:58
 * @Description:链表的中间节点-两次遍历法
 * https://leetcode-cn.com/problems/middle-of-the-linked-list/description/
 */
public class Solution876 {
    public ListNode middleNode(ListNode head) {
        int num = 0;
        ListNode temp = head;
        // 一次遍历结束，取得链表长度
        while (temp != null) {
            temp = temp.next;
            num ++;
        }
        int middle = num / 2;
        temp = head;
        for (int i = 0; i < middle; i++) {
            temp = temp.next;
        }
        return temp;
    }
}
